package isssr.control.src;

import javax.faces.event.NamedEvent;

import isssr.dao.exception.DAOException;
import isssr.dao.factory.DAOFactory;
import isssr.dao.interfaces.RoleDAO;
import isssr.dao.src.HibernateDAOFactory;
import isssr.dao.src.HibernateRoleDAO;
import isssr.entity.src.Role;
import isssr.entity.src.RoleDTO;


public class RoleControl {
	
	private Role role;
	private RoleDTO roleDTO;
	private RoleDAO roleDao;
	
	public RoleControl(){
		roleDao=DAOFactory.getDAOFactory().getRoleDAO();
		role=new Role("",0);
		roleDTO=role.getDTO();
	}
	
public void insert(RoleDTO roleDto){
		
		role.update(roleDto);
		
		try {
			roleDao.insert(role);
		} catch (DAOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
public void delete(RoleDTO roleDto){
	try {
		role=roleDao.getByTitle(roleDto.getTitle());
	} catch (DAOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	try {
		roleDao.delete(role);
	} catch (DAOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}

public Role getRole() {
	return role;
}

public void setRole(Role role) {
	this.role = role;
}

public RoleDTO getRoleDTO() {
	return roleDTO;
}

public void setRoleDTO(RoleDTO roleDTO) {
	this.roleDTO = roleDTO;
}

public RoleDAO getRoleDao() {
	return roleDao;
}

public void setRoleDao(RoleDAO roleDao) {
	this.roleDao = roleDao;
}



}
